from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from postion import options
from postion import service
from login_para import Login

url=r'http://192.168.92.131/upload/'
username = 'admin'
password = '123456'
driver=webdriver.Chrome(options=options,service=service)
driver.get(url)
driver.maximize_window()



# 登录
login = Login(driver)
login.login(username, password)
# driver.find_element(By.ID,'ls_username').clear()
# driver.find_element(By.ID,'ls_username').send_keys('admin')
# driver.find_element(By.ID,'ls_password').clear()
# driver.find_element(By.ID,'ls_password').send_keys('123456')
# sleep(3)
# driver.find_element(By.CLASS_NAME,'pn.vm').click()
# sleep(3)
def post():
    # 发贴
    driver.find_element(By.XPATH,'//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
    driver.find_element(By.ID,'newspecial').click()
    driver.find_element(By.ID,'subject').clear()
    driver.find_element(By.ID,'subject').send_keys('赵总异闻录')
    sleep(3)
    #嵌套页面
    driver.switch_to.frame('e_iframe')
    driver.find_element(By.XPATH,'/html/body').clear()
    driver.find_element(By.XPATH,'/html/body').send_keys('《异闻录》是赵总 [2]成为汤圆创作惊悚夜剧场说书人后，继《耳食者》 [3]之后，在2015年11月起在汤圆创作连载发布的又一个惊悚悬疑力作。')
    sleep(3)
    #跳回默认页面
    driver.switch_to.default_content()
    driver.find_element(By.ID,'postsubmit').click()
    sleep(3)
post()
#退出
login.logout()
# driver.find_element(By.LINK_TEXT,'退出').click()
# sleep(3)

driver.quit()